package cn.fengzhilun.javase.day01;

import java.util.Arrays;

import org.junit.Test;

public class test {
	@Test
	public void test() {
		int a []= {6,3,4,8,7,1};
		insertionSort(a);
		
	}
//插入排序
	public static  void insertionSort(int a[]) {
		
	for(int i=1;i<a.length;i++) {
		 int x=a[i];
		int j= i-1;
		while(j>=0&&x<a[j]) {
			a[j+1]=a[j];
			j--;
			
		}
		a[j+1]=x;
		System.out.println(Arrays.toString(a));

	}	
		System.out.println(Arrays.toString(a));
		
	}
}
